package com.sisreq.elementos;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JFormattedTextField;
import javax.swing.text.DefaultFormatterFactory;
import javax.swing.text.MaskFormatter;

@SuppressWarnings("serial")
public class MyDateField extends JFormattedTextField {

	public MyDateField() {
		try {
			MaskFormatter formatter = new MaskFormatter("##/##/####");
			formatter.setPlaceholderCharacter(' ');
			this.setFormatterFactory(new DefaultFormatterFactory(formatter));
			this.setColumns(8);
		} catch (ParseException ex) {
			ex.printStackTrace();
		}
	}

	public MyDateField(Date data) {
		try {
			MaskFormatter formatter = new MaskFormatter("##/##/####");
			formatter.setPlaceholderCharacter(' ');
			this.setFormatterFactory(new DefaultFormatterFactory(formatter));
			this.setColumns(8);
			SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
			this.setValue(format.format(data));
		} catch (ParseException ex) {
			ex.printStackTrace();
		}
	}

}
